<template>
  <div class>
    <div style="flex:1">
      <el-table :data="dataList" stripe size="mini" style="width: 100%;height:100%">
        <el-table-column prop="GOODS_NAME" header-align="center" align="center" label="特殊货物"></el-table-column>
        <el-table-column prop="GOODS_NUM" header-align="center" align="center" label="票数"></el-table-column>
        <el-table-column
          prop="TALLY_FINISH_TIME"
          show-overflow-tooltip
          header-align="center"
          align="center"
          label="理货完成时间"
        ></el-table-column>
        <el-table-column prop="OUTTIME_CHECK" header-align="center" align="center" label="超时检查：是/否"></el-table-column>
        <el-table-column
          prop="WAREHOUSE_CHECK"
          header-align="center"
          align="center"
          label="库位检查：符合/不符合"
        ></el-table-column>
        <el-table-column prop="EXCEPT_BILL" header-align="center" align="center" label="异常运单"></el-table-column>
        <el-table-column prop="CHECK_STATUS" header-align="center" align="center" label="核查情况">
          <template slot-scope="scope">
            <el-button type="text" v-if="scope.row.CHECK_STATUS=='1'" size="mini">已核查</el-button>
            <el-button
              type="primary"
              v-if="scope.row.CHECK_STATUS!='1'&&scope.row.checkFlag"
              size="mini"
              @click="changeStatus(scope.row)"
            >核查</el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="COFIM_USER_NAME"
          show-overflow-tooltip
          header-align="center"
          align="center"
          label="核查人"
        ></el-table-column>
        <el-table-column
          prop="MEMO"
          show-overflow-tooltip
          header-align="center"
          align="center"
          label="备注"
        ></el-table-column>
      </el-table>
    </div>
    <div style="padding: 20px 20px 0;text-align:right" v-if="formId">
      <el-button v-if="isAuthBtn('extra5')"  size="mini" type="success" @click="addDateForm()">新增</el-button>
    </div>

    <el-dialog
      title="新增"
      :close-on-click-modal="false"
      :visible.sync="visible"
      width="800px"
      append-to-body
    >
      <el-form
        label-width="110px"
        :inline="true"
        :model="dataForm"
        ref="dataForm"
        :rules="dataRule"
      >
        <el-form-item label="特殊货物">
          <el-input style="width:200px" v-model="dataForm.GOODS_NAME" placeholder></el-input>
        </el-form-item>
        <el-form-item label="票数">
          <el-input style="width:200px" type="number" v-model="dataForm.GOODS_NUM" placeholder></el-input>
        </el-form-item>
        <el-form-item label="理货完成时间">
          <el-date-picker
            style="width:200px"
            v-model="dataForm.TALLY_FINISH_TIME"
            type="date"
            value-format="yyyy-MM-dd HH:mm"
            format="yyyy-MM-dd HH:mm"
            placeholder="选择日期时间"
          ></el-date-picker>
        </el-form-item>
        <el-form-item label="库位检查 " prop="WAREHOUSE_CHECK">
          <el-radio-group v-model="dataForm.WAREHOUSE_CHECK">
            <el-radio label="符合"></el-radio>
            <el-radio label="不符合"></el-radio>
            <el-radio label="N/A"></el-radio>
          </el-radio-group>
        </el-form-item>
        <el-form-item label="超时检查" prop="OUTTIME_CHECK">
          <el-radio-group v-model="dataForm.OUTTIME_CHECK">
            <el-radio label="是"></el-radio>
            <el-radio label="否"></el-radio>
            <el-radio label="N/A"></el-radio>
          </el-radio-group>
        </el-form-item>
        <br />
        <el-form-item label="异常运单">
          <el-input style="width:200px" v-model="dataForm.AIR_TYPE" placeholder></el-input>
        </el-form-item>
      </el-form>
      <span slot="footer" class="dialog-footer">
        <el-button size="mini" @click="visible = false">取 消</el-button>
        <el-button type="primary" size="mini" @click="dataFormSubmit()">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import internalTab2 from "./internalTab2";
export default {
  props: {
    formId: {
      default: 0
    }
  },
  components: { internalTab2 },
  data() {
    return {
      visible: false,
      dataRule: {
        OUTTIME_CHECK: [
          { required: true, message: "超时检查不能为空", trigger: "blur" }
        ],
        WAREHOUSE_CHECK: [
          { required: true, message: "库位检查不能为空", trigger: "blur" }
        ]
      },
      dataForm: {
        GOODS_NAME: "",
        GOODS_NUM: "",
        TALLY_FINISH_TIME: "",
        WAREHOUSE_CHECK: "",
        AIR_TYPE: "",
        OUTTIME_CHECK: ""
      },
      dataList: []
    };
  },
  methods: {
    init(data) {
      this.dataList = data;
    },
    addDateForm() {
      this.dataForm = {
        REPORT_ID: sessionStorage.reportid,
        GOODS_NAME: "",
        GOODS_NUM: "",
        TALLY_FINISH_TIME: "",
        WAREHOUSE_CHECK: "",
        AIR_TYPE: "",
        OUTTIME_CHECK: ""
      };
      this.visible = true;
    },
    changeStatus(item) {
      this.$prompt("请输入备注", "提示", {
        confirmButtonText: "确定",
        inputPattern: /\S/,
        inputErrorMessage: "请输入备注",
        inputType: "textarea",
        cancelButtonText: "取消"
      }).then(({ value }) => {
        this.$http({
          url: this.$http.adornUrl(`/air/special_good_check`),
          method: "post",
          data: this.$http.adornData({
            ID: item.ID,
            REPORT_ID: item.REPORT_ID,
            GOODS_NAME: item.GOODS_NAME,
            CHECK_STATUS: "1",
            MEMO: value
          })
        }).then(({ data }) => {
          if (data.result == "1") {
            this.$message({
              message: "操作成功",
              type: "success",
              duration: 1500,
              onClose: () => {
                this.visible = false;
                this.$emit("refsherData", sessionStorage.reportid);
              }
            });
          } else {
            this.$message.error(data.message);
          }
        });
      });
    },
    dataFormSubmit() {
      this.$http({
        url: this.$http.adornUrl(`/air/special_good_save`),
        method: "post",
        data: this.$http.adornData(this.dataForm)
      }).then(({ data }) => {
        if (data.result == "1") {
          this.$message({
            message: "操作成功",
            type: "success",
            duration: 1500,
            onClose: () => {
              this.visible = false;
              this.$emit("refsherData", this.dataForm.REPORT_ID);
            }
          });
        } else {
          this.$message.error(data.message);
        }
      });
    }
  }
};
</script>

<style lang="scss">
.reportBox {
  border: 2px solid #eee;
  width: 900px;
  margin: 10px;
}
.boxRow {
  display: flex;
  border-bottom: 1px solid #e6e6e6;
}
.nb {
  border-bottom: none;
}
.br {
  border-right: 1px solid #e6e6e6;
}
.boxtitle {
  padding: 20px;
}
.rowItem {
  flex: 1;
  padding-left: 20px;
  display: flex;
  align-items: center;
}
.pr20 .rowItem {
  padding-right: 20px;
}
.table--border {
  margin-top: 10px;
}

.tborders {
  width: 900px;
  margin: 10px auto;
  display: flex;
  flex-direction: column;
}
</style>